﻿
using AnQinManagermentBackendAPI.Model.DTO.Project;
using AnQinManagermentBackendAPI.Model.View.Project;
using AnQinManagermentBackendAPI.Service;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace AnQinManagermentBackendAPI.Controller
{
    /// <summary>
    /// 项目表
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class ProjectController : ControllerBase
    {
        /**
         * 项目业务接口
         */
        private readonly ProjectService _projectService;

        /**
         * 构造函数注入
         */
        public ProjectController(ProjectService projectService)
        {
            _projectService = projectService;
        }

        /// <summary>
        /// 获取项目列表
        /// </summary>
        /// <param name="projectSearchDTO"></param>
        [HttpGet]
        [ProducesResponseType(typeof(ProjectView), 200)]
        public async Task<IActionResult> GetProjectList([FromQuery] ProjectSearchDTO projectSearchDTO)
        {
            var response = await _projectService.GetProjectList(projectSearchDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 新增项目
        /// </summary>
        /// <param name="projectAddDTO"></param>
        [HttpPost]
        public async Task<IActionResult> AddProject([FromBody] ProjectAddDTO projectAddDTO)
        {
            var response = await _projectService.AddProject(projectAddDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 更新项目
        /// </summary>
        /// <param name="projectUpdateDTO"></param>
        [HttpPut]
        public async Task<IActionResult> PutProject([FromBody] ProjectUpdateDTO projectUpdateDTO)
        {
            var response = await _projectService.PutProject(projectUpdateDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 删除项目
        /// </summary>
        [HttpDelete]
        public async Task<IActionResult> DeleteProject([FromQuery] string Id)
        {
            var response = await _projectService.DeleteProject(Id);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 删除项目
        /// </summary>
        [HttpPost("AfterSale")]
        public async Task<IActionResult> AfterSaleProject([FromBody] string Id)
        {
            var response = await _projectService.AfterSaleProject(Id);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 项目下拉列表 - 开发管理
        /// </summary>
        [HttpGet("/Development/Select")]
        public async Task<IActionResult> DevelopmentSelectProject()
        {
            var response = await _projectService.DevelopmentSelectProject();
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 项目下拉列表 - 实施管理
        /// </summary>
        [HttpGet("/Implement/Select")]
        public async Task<IActionResult> ImplementSelectProject()
        {
            var response = await _projectService.ImplementSelectProject();
            return StatusCode(response.Status, response);
        }
    }
}
